import { Modal, ModalConfig } from '@arco-design/web-vue';
import type { RenderContent } from '@arco-design/web-vue/es/_utils/types';

// 创建自定义的配置类型，继承自 ModalConfig 但所有属性都是可选的
interface CustomModalConfig extends Partial<ModalConfig> {
  title?: string;
  content?: RenderContent;
  onOk?: () => void;
  onCancel?: () => void;
  titleAlign?: 'start' | 'center';
  simple?: boolean;
  closable?: boolean;
  hideCancel?: boolean;
}

// 封装确认对话框函数
const useConfirmDialog = ({
  title = '确认操作',
  content = '你确定要执行此操作吗？',
  onOk = () => {},
  onCancel = () => {},
  titleAlign = 'start',
  simple = false,
  closable = true,
  hideCancel = false,
}: CustomModalConfig = {}) =>
  Modal.warning({
    title,
    content,
    titleAlign,
    simple,
    closable,
    hideCancel,
    onOk: () => {
      if (typeof onOk === 'function') {
        onOk();
      }
    },
    onCancel: () => {
      if (typeof onCancel === 'function') {
        onCancel();
      }
    },
  });

export default useConfirmDialog;
